//变量引进
var accessId = getParameter("x-access-id");
var accessToken = getParameter("x-access-token");
var customerId = getParameter("customerId");
var versionCode=getParameter("x-version-code");
var ua = "h5";
/*ajax调用*/
function jsonAjax(url,type,data,callback) {
    $.ajax({
        url:url,
        type: type,
        contentType:"application/json",
        dataType:'json',
        async:false,
        data:data,
        headers:{
            "x-access-id": accessId,
            "x-access-token": accessToken,
            "x-ua": ua,
            "x-version-code":versionCode
        },
        success: callback
    });
}
/*初始化*/
$(function () {
    /*个人主页*/
    personal();
    /*个人信息*/
   // personalInfo();
    /*个人动态*/
    personalDy();
    /*谁看过他*/
    seeHer();
    /*送出的礼物*/
    giftOut();
});
/*个人主页*/
function personal() {
    var data={
        "customerId":customerId
    };
    jsonAjax(genUrl("/h5/customer/home"),'GET',data,personfun);
}
function personfun(res){
    if(res.code==0){
        /*相册渲染*/
        var data = res.data;
        var alums = data.album.split(",");
        alums.unshift(data.photo);
        var alumsT = "";
        for (var i = 0; i < alums.length; i++) {
            alumsT += '<div class="swiper-slide"><img src="' + alums[i] + '" alt=""></div>';
        }
        $("#alum").append(alumsT);
        /*年龄+魅力值*/
        var birthday = data.birthday.split("-")[0];
        var nowday = new Date().getFullYear();
        var age = $("#age").text((nowday - birthday) + "岁");
        var charmValue = $("#ptwo").text("接通率100%");
        if(data.sex==0){
            $("#sex").html("GIRL");
        }else if(data.sex==1){
            $("#sex").html("BOY");
        }
        /*个性签名*/
        if(data.customerExtInfoDto.signature==""){
            $("#sigle").html("这家伙太懒了，什么也没有留下...");
        }else{
            $("#sigle").html(data.customerExtInfoDto.signature);
        }

        /*聊天能力*/
        var chatlist = data.chatTheme.split(',');
        var chat = "";
        if(chatlist==""){
            $("#chatTheme").html("ta还没设置聊天能力");
        }else{
            for (var i = 0; i < chatlist.length; i++) {
                chat += '<span>' + chatlist[i] + '</span>';
            }
            $("#chatTheme").append(chat);
        }


        /*收到礼物*/
        var gifts = "";
        var customerGiftList = JSON.parse(data.customerGiftList);
        $("#giftcount").text("(" + customerGiftList.length + ")");
        var len="";
        if(customerGiftList.length==0){
            $("#gift").html("ta还未收到礼物！");
        }else if(customerGiftList.length>5){
            len=5;
        }else{
            len=customerGiftList.length;
        }
        for (var i = 0; i <len; i++) {
            var giftpic = customerGiftList[i].giftImage;
            gifts += '<span><img src="' + giftpic + '" alt=""></span>'
        }
        $("#gift").append(gifts);
        /*昵称*/
        $("#nickName b").text(data.nickName);
        $("#nickName span").text(data.customerId);
        /*个人信息*/
       var personinfo=data.anchorBaseInfoDto;
        if(personinfo !=null){
            var data=res.data;
            var fun= function(ele) {
                if(ele==undefined){
                    ele="/"
                }
                return ele;
            }
            //情感删选
            switch (Number(personinfo.emotionStatus)){
                case 1:
                    emotionStatus= "保密";
                    break;
                case 2:
                    emotionStatus= "单身";
                    break;
                case 3:
                    emotionStatus= "恋爱中";
                    break;
                case 4:
                    emotionStatus= "已婚";
                    break;
                case 5:
                    emotionStatus= "离异";
                    break;
                case 6:
                    emotionStatus= "同性";
                    break;
                default:
                    emotionStatus= "/";
            }
            //星座删选
            switch (Number(personinfo.constellationType)){
                case 1:
                    constellationType= "白羊座";
                break;
                case 2:
                    constellationType= "金牛座";
                    break;
                case 3:
                    constellationType= "双子座";
                    break;
                case 4:
                    constellationType= "巨蟹座";
                    break;
                case 5:
                    constellationType= "狮子座";
                    break;
                case 6:
                    constellationType= "处女座";
                    break;
                case 7:
                    constellationType= "天秤座";
                    break;
                case 8:
                    constellationType= "天蝎座";
                    break;
                case 9:
                    constellationType= "射手座";
                    break;
                case 10:
                    constellationType= "摩羯座";
                    break;
                case 11:
                    constellationType= "水瓶座";
                    break;
                case 12:
                    constellationType= "双鱼座";
                    break;
                default:
                    constellationType= "/";
            }
            //血型筛选
            switch (Number(personinfo.bloodType)){
                case 1:
                    bloodType= "A型";
                    break;
                case 2:
                    bloodType= "B型";
                    break;
                case 3:
                    bloodType= "O型";
                    break;
                case 4:
                    bloodType= "AB型";
                    break;
                case 5:
                    bloodType= "其他";
                    break;
                default:
                    bloodType= "/";
            }
            //胸围筛选
            switch (Number(personinfo.chestCupType)){
                case 1:
                    chestCupType= "A杯";
                    break;
                case 2:
                    chestCupType= "B杯";
                    break;
                case 3:
                    chestCupType= "C杯";
                    break;
                case 4:
                    chestCupType= "D杯";
                    break;
                case 5:
                    chestCupType= "E杯";
                    break;
                case 6:
                    chestCupType= "F杯";
                    break;
                default:
                    chestCupType= "/";
            }
            //是否接受约会
            switch (Number(personinfo.acceptDateType)){
                case 1:
                    acceptDateType= "是";
                    break;
                case 2:
                    acceptDateType= "否";
                    break;
                default:
                    acceptDateType= "/";
            }
        }
        var str="";
        str+="<span>家乡："+fun(data.city)+"</span>\n" +
            "<span>情感："+fun(emotionStatus)+"</span>\n" +
            "<span>星座："+fun(constellationType)+"</span>\n" +
            "<span>血型："+fun(bloodType)+"</span>\n" +
            "<span>签名："+fun(data.customerExtInfoDto.signature)+"</span>\n" +
            "<span>职业："+fun(data.job)+"</span>\n" +
            "<span>性格："+fun(personinfo.character)+"</span>\n" +
            "<span>身高："+fun(personinfo.height)+"cm</span>\n" +
            "<span>体重："+fun(personinfo.weight)+"kg</span>\n" +
            "<span>胸围："+fun(chestCupType)+"</span>\n" +
            "<span>腰围："+fun(personinfo.waistline)+"cm</span>\n" +
            "<span>臀围："+fun(personinfo.hips)+"cm</span>\n" +
            "<span>常去场所："+fun(personinfo.oftenGoArea)+"</span>\n" +
            "<span>是否接受约会："+fun(acceptDateType)+"</span>\n" +
            "<span>注册位置："+fun(data.customerExtInfoDto.registerCity)+"</span>\n" +
            "<span>当前位置："+fun(data.customerExtInfoDto.currentCity)+"</span>";
        $("#info").html(str);
        }else{
            console.log("个人信息查询错误"+res.message);
    }
}
/*个人动态*/
function  personalDy(){
    var data={
        "customerId":customerId,
        "beginId":0
    };
    jsonAjax(genUrl("/h5/dynamic/list/own"),'GET',data,personalDyfun);
}
function personalDyfun(res){
    if(res.code==0){
        var dypic=res.data.dynamics;
        if(dypic.length==0){
            $("#dypic").html("ta还未发表过动态！");
        }else{
            var pics="";
            var pics2="";
            var imgss="";
            if(dypic && dypic.length>0){
                for(var i=0;i<dypic.length;i++){
                    if(dypic[i].imgUrl.imgUrls && dypic[i].imgUrl.imgUrls.length ){
                        for(var j=0;j<dypic[i].imgUrl.imgUrls.length;j++){
                            if(dypic[i].imgUrl.imgUrls[j].indexOf(".mp3")<0){
                                pics+='<span><img src='+dypic[i].imgUrl.imgUrls[j]+' alt=""></span>';
                            }
                        }
                    }
                }
                $("#dypic").html(pics);
                $("#dycount").text("("+dypic.length+")");
                var spanlist=$("#dypic").find('span');
                var len="";
                if(spanlist.length>5){
                    len=5;
                }else{
                    len=spanlist.length;
                }
                for(var i=0;i<len;i++){
                    pics2+='<span><img src='+spanlist[i].childNodes[0].src+' alt=""></span>';
                }
                $("#dypic").html(pics2);
            }

        }
    }else{
        console.log("个人动态错误"+res.message);
    }
}
/*谁看过他*/
function  seeHer(){
    data={
        "customerId":customerId
    };
    jsonAjax(genUrl("/app/getAccessToMyList"),'GET',data,seeHerfun);
}
function seeHerfun(res){
    if(res.code==0){
        var seelist=res.data;
        if(seelist.length==0){
            $("#dysee").html('还没有人看过ta!');
        }else{
            var seepic="";
            var len="";
            if(seelist.length>5){
                len=5;
            }else{
                len=seelist.length;
            }
            for(var i=0;i<len;i++){
                seepic+='<span><img src="'+seelist[i].photo+'" alt=""></span>'
            }
            $("#dysee").html(seepic);
        }
    }else{
        console.log("看过当前用户列表出错"+res.message);
    }
}
/*送出的礼物*/
function giftOut(){
    var data={
        "customerId":customerId,
        "beginId":0
    };
    jsonAjax(genUrl("/gift/list/all"),'GET',data,giftOutfun);
}
function giftOutfun(res){
    if(res.code==0){
        var privateStatus=res.data.customerPrivateInfo.privateStatus;
        if(privateStatus==1){
            $("#giftoutpic").html("ta开启了隐私保护，隐藏了礼物！");
        }else{
            var giftOutLsit=res.data.giftTrades;
            if(giftOutLsit.length==0){
                $("#giftoutpic").html('ta还未送出礼物！');
                $("#giftoutcount").text('');
            }else{
                var len="";
                var gol='';
                if(giftOutLsit.length<=5){
                    len=giftOutLsit.length;
                }else{
                    len=5;
                }
                for(var i=0;i<len;i++){
                    gol+='<span><img src="'+giftOutLsit[i].giftItem.giftImage+'" alt=""></span>';
                }
                $("#giftoutpic").html(gol);
                $("#giftoutcount").text("("+giftOutLsit.length+")");
            }
        }
    }else{
        console.log("送出礼物查询列表出现错误"+res.message);
    }
}







